package com.firestone.dao.primary.center;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.firestone.bean.dto.terminal.TerminalDTO;
import com.firestone.bean.entity.mysql.primary.ImCenterTerminalMenu;

/**
 * <p>
 * 具体分支系统菜单 Mapper 接口
 * </p>
 *
 * @author CAIYJ
 * @since 2018-03-27
 */
public interface ImCenterTerminalMenuDao
        extends BaseMapper<ImCenterTerminalMenu> {

    /**
     * @Description: TODO(根据管理员ID查询权限url列表)
     * @param id
     * @return
     * @author CAIYJ
     * @date 2018年3月30日 上午10:05:55
     * @lastModifier CAIYJ
     */
    @Select("SELECT im_center_terminal_menu.url_ids FROM im_center_terminal_menu "
            + "INNER JOIN im_center_menu ON im_center_menu.id = im_center_terminal_menu.menu_id "
            + "INNER JOIN im_center_role_r_menu ON im_center_role_r_menu.menu_id = im_center_menu.id "
            + "INNER JOIN im_center_role ON im_center_role.id = im_center_role_r_menu.role_id "
            + "INNER JOIN im_center_manager_r_role ON im_center_manager_r_role.role_id = im_center_role.id "
            + "WHERE im_center_manager_r_role.manager_id = #{id}")
    List<String> getUrlsByManagerId(@Param("id") Long id);

    /**
     * @Description: TODO(终端菜单权限列表)
     * @param pagination
     * @param wrapper
     * @return
     * @author CAIYJ
     * @date 2018年3月30日 上午10:09:53
     * @lastModifier CAIYJ
     */
    @Select("<script>  "
            + "SELECT ctm.id, ctm.`name`, ctm.create_time, ctm.update_time, cm.real_name AS create_user, cm1.real_name AS update_user "
            + "FROM im_center_terminal_menu AS ctm "
            + "LEFT JOIN im_center_manager AS cm ON cm.id = ctm.creator "
            + "LEFT JOIN im_center_manager AS cm1 ON cm1.id = ctm.reviser "
            + "<where> ${ew.sqlSegment} </where> </script> ")
    <T> List<TerminalDTO> selectTerminalList(Pagination pagination,
            @Param("ew") Wrapper<T> wrapper);
}
